package com.mofeng.myshop.service.fileupload.factory;

import com.mofeng.myshop.service.fileupload.FileServer;
import com.mofeng.myshop.until.Constants;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class FileFactory {
    public final Map<String, FileServer> fileServerMap = new HashMap<>();

    private FileFactory(Map<String, FileServer> serverMap) {
        fileServerMap.putAll(serverMap);
    }

    public FileServer getServer(String key) {
        String type = Constants.Settings.FILE_UPLOAD_TYPE + key;
        FileServer fileServer = fileServerMap.get(type);
        if (fileServer == null) {
            throw new RuntimeException("找不到文件上传方式 " + key);
        }
        return fileServer;
    }
}
